expo <- function(x, rate){
return(2.78^(-rate*x))
}
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_ESC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "101515.C3_ESC",]
gpXY <- ggplot_setup(TRUE)
gpXY <- gpXY + geom_density(data=x1, aes(`Corrected XY_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XY Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXY <- gpXY + geom_density(data=x2, aes(`Corrected XY_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0, linetype=2)
gpXY
## Warning: Removed 7 rows containing non-finite values (stat_density).
## Warning: Removed 2 rows containing non-finite values (stat_density).
gpXYZ <- ggplot_setup(TRUE)
gpXYZ <- gpXYZ + geom_density(data=x1, aes(`Corrected XYZ_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XYZ Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXYZ <- gpXYZ + geom_density(data=x2, aes(`Corrected XYZ_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0, linetype=2)
gpXYZ
## Warning: Removed 113 rows containing non-finite values (stat_density).
## Warning: Removed 11 rows containing non-finite values (stat_density).
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "013116.2G8_ESC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "013116.2G8_ESC",]
gpXY <- ggplot_setup(TRUE)
gpXY <- gpXY + geom_density(data=x1, aes(`Corrected XY_Distance (um)`), color="salmon", fill="salmon", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XY Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXY <- gpXY + geom_density(data=x2, aes(`Corrected XY_Distance (um)`), color="salmon", fill="salmon", alpha=0.3, size=1.0, linetype=2)
gpXY
## Warning: Removed 76 rows containing non-finite values (stat_density).
## Warning: Removed 1 rows containing non-finite values (stat_density).
gpXYZ <- ggplot_setup(TRUE)
gpXYZ <- gpXYZ + geom_density(data=x1, aes(`Corrected XYZ_Distance (um)`), color="salmon", fill="salmon", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XYZ Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXYZ <- gpXYZ + geom_density(data=x2, aes(`Corrected XYZ_Distance (um)`), color="salmon", fill="salmon", alpha=0.3, size=1.0, linetype=2)
gpXYZ
## Warning: Removed 204 rows containing non-finite values (stat_density).
## Warning: Removed 9 rows containing non-finite values (stat_density).
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "013116.2G8_ESC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "013116.2G8_ESC",]
#20sec data
length(unique(x1$C1_Image))
## [1] 80
#4sec data
length(unique(x2$C1_Image))
## [1] 29
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_NPC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "101515.C3_NPC",]
gpXY <- ggplot_setup(TRUE)
gpXY <- gpXY + geom_density(data=x1, aes(`Corrected XY_Distance (um)`), color="tan", fill="tan", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XY Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXY <- gpXY + geom_density(data=x2, aes(`Corrected XY_Distance (um)`), color="tan", fill="tan", alpha=0.3, size=1.0, linetype=2)
gpXY
## Warning: Removed 21 rows containing non-finite values (stat_density).
gpXYZ <- ggplot_setup(TRUE)
gpXYZ <- gpXYZ + geom_density(data=x1, aes(`Corrected XYZ_Distance (um)`), color="tan", fill="tan", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XYZ Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXYZ <- gpXYZ + geom_density(data=x2, aes(`Corrected XYZ_Distance (um)`), color="tan", fill="tan", alpha=0.3, size=1.0, linetype=2)
gpXYZ
## Warning: Removed 37 rows containing non-finite values (stat_density).
####How many cells are included in each set?
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_NPC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "101515.C3_NPC",]
#20sec data
length(unique(x1$C1_Image))
## [1] 138
#4sec data
length(unique(x2$C1_Image))
## [1] 17
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "022616.1C5_ESC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "022616.1C5_ESC",]
gpXY <- ggplot_setup(TRUE)
gpXY <- gpXY + geom_density(data=x1, aes(`Corrected XY_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XY Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXY <- gpXY + geom_density(data=x2, aes(`Corrected XY_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0, linetype=2)
gpXY
## Warning: Removed 7 rows containing non-finite values (stat_density).
gpXYZ <- ggplot_setup(TRUE)
gpXYZ <- gpXYZ + geom_density(data=x1, aes(`Corrected XYZ_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XYZ Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXYZ <- gpXYZ + geom_density(data=x2, aes(`Corrected XYZ_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0, linetype=2)
gpXYZ
## Warning: Removed 53 rows containing non-finite values (stat_density).
## Warning: Removed 5 rows containing non-finite values (stat_density).
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "022616.1C5_ESC",]
x2 <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "022616.1C5_ESC",]
#20sec data
length(unique(x1$C1_Image))
## [1] 84
#4sec data
length(unique(x2$C1_Image))
## [1] 76
x1 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_ESC",]
x2 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "022616.1C5_ESC",]
gpXY <- ggplot_setup(TRUE)
gpXY <- gpXY + geom_density(data=x1, aes(`Corrected XY_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XY Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXY <- gpXY + geom_density(data=x2, aes(`Corrected XY_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0)
gpXY
## Warning: Removed 7 rows containing non-finite values (stat_density).
## Warning: Removed 7 rows containing non-finite values (stat_density).
gpXYZ <- ggplot_setup(TRUE)
gpXYZ <- gpXYZ + geom_density(data=x1, aes(`Corrected XYZ_Distance (um)`), color="lightblue", fill="lightblue", alpha=0.3, size=1.0) + scale_x_continuous(limits=c(0,1.0), breaks=c(0, 0.25, 0.5, 0.75, 1.0)) + xlab("XYZ Distance (um)") + ylab("Normalized Density") + theme(axis.line.x = element_line(size=1.2, color="white"), axis.line.y = element_line(size=1.2, color="white")) + scale_y_continuous(limits=c(0,6), breaks=c(0, 2, 4, 6))
gpXYZ <- gpXYZ + geom_density(data=x2, aes(`Corrected XYZ_Distance (um)`), color="purple", fill="purple", alpha=0.3, size=1.0)
gpXYZ
## Warning: Removed 113 rows containing non-finite values (stat_density).
## Warning: Removed 53 rows containing non-finite values (stat_density).
x_tot <- Sox2_data_unsync_20sec
cell_lines <- unique(x_tot$Cell_Line)
for (l in cell_lines){
x <- x_tot[x_tot$Cell_Line == l,]
images <- unique(x$C1_Image)
full_tracks <- c()
mean_distance <- c()
for (i in images){
if (length(x[x$C1_Image == i, "C1_T Value (frame)"]) > 90){
full_tracks <- c(full_tracks, i)
mean_distance <- c(mean_distance, mean(x[x$C1_Image == i, "Corrected XYZ_Distance (um)"]))
}
}
df <- data.frame(full_tracks, mean_distance)
df
r_im <- df
#r_im <- df[sample(nrow(df), 20, replace = FALSE),]
r_im <- r_im[order(r_im$mean_distance),]
xsub <- x[x$C1_Image %in% r_im$full_tracks,]
xsub$C1_Image <- factor(xsub$C1_Image, levels=r_im$full_tracks)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_jitter(data=xsub, aes(x=`C1_Image`, y=`Corrected XYZ_Distance (um)`), pch=16, col="purple") + ylim(0,1)
mval <- mean(x$`Corrected XYZ_Distance (um)`)
lowq <- quantile(x$`Corrected XYZ_Distance (um)`, probs = 0.25)
hiq <- quantile(x$`Corrected XYZ_Distance (um)`, probs = 0.75)
gp <- gp + geom_hline(yintercept = mval, size=0.75, linetype="dotted", color="white") + geom_hline(yintercept = lowq, size=0.75, linetype="dotted", color="yellow") + geom_hline(yintercept = hiq, size=0.75, linetype="dotted", color="yellow") + xlab("Cells") + ylab("XYZ Distance (um)") + ggtitle(paste("Cell-to-cell Heterogeneity of Distance Measurements ", l, sep=""))
print(gp)
hist(mean_distance, breaks=20, xlim=c(0,0.8))
}
## Warning: Removed 83 rows containing missing values (geom_point).
## Warning: Removed 96 rows containing missing values (geom_point).
## Warning: Removed 18 rows containing missing values (geom_point).
## Warning: Removed 3 rows containing missing values (geom_point).
## Warning: Removed 18 rows containing missing values (geom_point).
x <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "101515.C3_ESC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
gp
##4sec
x <- Sox2_data_4sec[Sox2_data_4sec$Cell_Line == "101515.C3_ESC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
##20sec
x2 <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_ESC",]
images <- unique(x2$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x2[x2$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac2 <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac2[i + 1] <- mean(cc, na.rm=TRUE)
}
gp <- gp + geom_line(aes(x=seq(0,(length(ac2) - 1), by=1),y=ac2), color="red", size=1.2, linetype=2)
gp
x <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_ESC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 90
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1)), y=dexp(x=seq(0,(length(ac) - 1)), rate = 1.0), color="red", linetype=3)
gp
x <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "022616.1C5_ESC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
gp
x <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_NPC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
gp
x <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "013116.2G8_NPC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 80
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
gp
###Ongoing Analysis
x <- Sox2_data_unsync_20sec[Sox2_data_unsync_20sec$Cell_Line == "101515.C3_ESC",]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 90
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1))
df <- data.frame(x=seq(0,(length(ac) - 1)), y=ac)
insertList = list(a=1,b=-0.01,c=1,d=-0.1)
exp.model <- nls(y ~ a*exp(b*x) + c*exp(d*x), data=df, start=insertList, control=list(maxiter=10000, minFactor=1/6096))
exp.model
## Nonlinear regression model
## model: y ~ a * exp(b * x) + c * exp(d * x)
## data: df
## a b c d
## 0.63763 -0.02231 0.34934 -0.68543
## residual sum-of-squares: 0.02286
##
## Number of iterations to convergence: 16
## Achieved convergence tolerance: 6.145e-06
params <- exp.model$m$getPars()
gp <- gp + geom_line(aes(x=seq(-2,100, by=0.01), y=params["a"]*expo(x = seq(-2,100, by=0.01), rate = params["b"]) + params["c"]*expo(x = seq(-2,100, by=0.01), rate = params["d"])), linetype="dotted", color="red", size=0.5)
gp
## Warning: Removed 9996 rows containing missing values (geom_path).
x_tot <- Sox2_data_unsync_20sec
cell_lines <- unique(x_tot$Cell_Line)
for (l in cell_lines){
x <- x_tot[x_tot$Cell_Line == l,]
images <- unique(x$C1_Image)
m <- matrix(nrow = length(images), ncol = 100, data = NA)
for (i in 1:length(images)){
x_sub <- x[x$C1_Image == images[i],]
frames <- x_sub$`C1_T Value (frame)`
for (j in frames){
m[i, j] <- x_sub[x_sub$`C1_T Value (frame)` == j, "Corrected XY_Distance (um)"]
}
}
maxlag <- 90
numframes <- 100
df <- m
ndata <- length(m[!is.na(m)])
nseries <- nrow(df)
m_value <- mean(df, na.rm=TRUE)
variance <- sd(df, na.rm=TRUE)^2
ac <- array(NA, dim = (maxlag + 1))
for (i in 0:maxlag){
cc <- c()
for (j in 1:nseries){
for (t in 1:(numframes - i)){
cc <- c(cc, ((df[j,t] - m_value) * (df[j, (t + i)] - m_value))/variance)
}
}
ac[i + 1] <- mean(cc, na.rm=TRUE)
}
#ac <- autocor_series(data=m, seriesbycol = FALSE, maxlag = 40, frames = 100)
gp <- ggplot_setup(TRUE)
gp <- gp + geom_line(aes(x=seq(0,(length(ac) - 1), by=1),y=ac), color="white", size=1.2)
ci95 <- 1.96 / sqrt(ndata)
gp <- gp + geom_hline(yintercept = ci95, linetype="dotted", color="blue", size=1.0) + geom_hline(yintercept = -ci95, linetype="dotted", color="blue", size=1.0) + xlab("Time lag (frames)") + ylab("Autocorrelation") + scale_y_continuous(limits = c(-1,1)) + ggtitle(paste("Autocorrelation with Two-term Exponential for line ", l, sep=""))
df <- data.frame(x=seq(0,(length(ac) - 1)), y=ac)
insertList = list(a=0.5,b=-0.02,c=0.5,d=-0.5)
exp.model <- nls(y ~ a*exp(b*x) + c*exp(d*x), data=df, start=insertList, control=list(maxiter=10000, minFactor=1/6096))
exp.model
params <- round(exp.model$m$getPars(), digits=2)
gp <- gp + geom_line(aes(x=seq(-2,100, by=0.01), y=params["a"]*expo(x = seq(-2,100, by=0.01), rate = -params["b"]) + params["c"]*expo(x = seq(-2,100, by=0.01), rate = -params["d"])), linetype="dotted", color="red", size=0.5)
gp <- gp + geom_text(aes(x=75, y=0.95, label=paste("y=", params["a"], "e^(", params["b"], "t) + ", params["c"], "e^(", params["d"], "t)", sep="")), color="red")
print(gp)
}
## Warning: Removed 197 rows containing missing values (geom_path).
## Warning: Removed 200 rows containing missing values (geom_path).
## Warning: Removed 199 rows containing missing values (geom_path).
## Warning: Removed 200 rows containing missing values (geom_path).
## Warning: Removed 200 rows containing missing values (geom_path).
## Warning: Removed 197 rows containing missing values (geom_path).
## Warning: Removed 200 rows containing missing values (geom_path).